package edu.gmu.swe632.fruit.activity;

import edu.gmu.swe632.fruit.service.GestureRecognizerService;
import android.app.ListActivity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class FruitActivity extends ListActivity
{
	private static final String TAG = "fruit";

	private static final String[] listItems = { "Start App", "Train Gestures" };

	private static final Class<?> nextIntentClasses[] = { FruitMainActivity.class,
			TrainGestureListActivity.class };

	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		Log.d(TAG, "onCreate");

		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
				listItems));

		GestureRecognizerService.mPackageName = getApplicationContext().getPackageName();
		startService(new Intent(this, GestureRecognizerService.class));
	}

	@Override
	public void onDestroy()
	{
		super.onDestroy();
		Log.d(TAG, "onDestroy");

		stopService(new Intent(this, GestureRecognizerService.class));
	}

	@Override
	public void onListItemClick(ListView parent, View v, int position, long id)
	{
		startNextActivity(position);
	}

	private void startNextActivity(int index)
	{
		if (0 <= index && index < nextIntentClasses.length)
		{
			Intent intent = new Intent(this, nextIntentClasses[index]);
			startActivity(intent);
		}
	}
}
